import { getSecond , uuid } from '../../utils/common'
import { Suggest } from '../../models/'
import { CODE } from '../../config/config'



/**
 * @api {post} /suggest/suggest 意见建议
 * @apiPermission 用户
 * @apiVersion 1.0.0 
 * @apiName suggest
 * @apiGroup suggest
 * @apiExample 请求示例:
 * curl -H "Content-Type: application/json" -X POST -d '{}' 'http://copyright.hotchain.vip/api/suggest/suggest'
 *
 * @apiParam {String}   main               意见内容
 * @apiParam {String}   qq                 qq
 * @apiParam {String}   email              邮箱
 * @apiParam {String}   phone              手机
 * @apiParam {String}   remark             备注
 * @apiParam {String}   ext                拓展字段
 * @apiParam {String}   name               姓名
 * 
 * @apiSuccess {Object}   suggest            意见对象
 * @apiSuccess {String}   main               意见内容
 * @apiSuccess {String}   qq                 qq
 * @apiSuccess {String}   email              邮箱
 * @apiSuccess {String}   phone              手机
 * @apiSuccess {String}   remark             备注
 * @apiSuccess {String}   ext                拓展字段
 * @apiSuccess {String}   name               姓名
 * @apiSuccess {String}   ctime              创建时间
 * 
 * @apiSampleRequest http://copyright.hotchain.vip/api/suggest/suggest
 * @apiSuccessExample {json} 成功返回
 *     HTTP/1.1 200 OK
 *     {
    "code": 0
  }
 *
 * @apiUse ERROR
 * 
 */

export async function suggest (ctx) {

	const main               = ctx.request.body.main
	const qq                 = ctx.request.body.qq
	const email              = ctx.request.body.main
	const phone              = ctx.request.body.phone
	const remark             = ctx.request.body.remark
	const ext                = ctx.request.body.ext
	const ctime              = getSecond()
	const id                 = uuid()
	const name               = ctx.request.body.name

	const suggest            = await Suggest.create({id,main,qq,email,phone,remark,ext,ctime,name})
	ctx.body                 = CODE.success({suggest})
}


/**
 * @apiDefine ERROR
 * @apiErrorExample {json} 错误返回:
 *     {
 *       "code": "错误码",
 *       "error": "错误描述",
 *       "msg":"错误信息"
 *     }
 */